FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PIP_DEFAULT_TIMEOUT=100
WORKDIR /code

# Install Poetry
RUN apt clean && apt update && apt install curl -y
# RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
#     cd /usr/local/bin && \
#     ln -s /opt/poetry/bin/poetry && \
#     poetry config virtualenvs.create false
# 配置pip使用阿里云镜像
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
    pip config set install.trusted-host mirrors.aliyun.com

RUN pip install poetry==2.2.1
# RUN poetry config virtualenvs.create false

# ----- Poetry 镜像 -----
RUN poetry config repositories.aliyun https://mirrors.aliyun.com/pypi/simple/ && \
    poetry config http-basic.aliyun __token__ "" && \
    poetry config installer.max-workers 10 && \
    poetry config virtualenvs.create false

ENV POETRY_REPOSITORIES_PYPI_URL=https://mirrors.aliyun.com/pypi/simple/
ENV POETRY_REPOSITORIES_PYPI_DEFAULT=true

# Copy poetry.lock* in case it doesn't exist in the repo
COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

ENV PYTHONPATH=/code
EXPOSE 8000
